package cn.edu.sdjzu.knoverse.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.edu.sdjzu.knoverse.model.dto.system.user.AssignRolesToUsersDto;
import cn.edu.sdjzu.knoverse.model.vo.result.Result;
import  cn.edu.sdjzu.knoverse.service.UserRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户和角色
 */
@Tag(name = "用户和角色", description = "用户和角色相关接口")
@RestController
@RequestMapping("/userRole")
public class UserRoleController {

    @Autowired
    private UserRoleService userRoleService;

    @SaCheckPermission("userRole::getRoleListByUserId")
    @Operation(summary = "根据用户id获取角色列", description = "根据用户id获取角色列")
    @GetMapping("getRoleListByUserId")
    public Result<List<String>> getRoleListByUserId(Long userId) {
        List<String> roleVoList = userRoleService.getRoleListByUserId(userId);
        return Result.success(roleVoList);
    }

    @SaCheckPermission("userRole::assignRolesToUsers")
    @Operation(summary = "为用户分配角色", description = "为用户分配角色")
    @PostMapping("assignRolesToUsers")
    public Result<String> assignRolesToUsers(@RequestBody AssignRolesToUsersDto dto) {
        userRoleService.assignRolesToUsers(dto);
        return Result.success();
    }
}
